package core;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.Point2D;

import javax.swing.ImageIcon;

public class Base extends Unit {
	
	private static final ImageIcon image = new ImageIcon(Base.class.getResource("../images/baseintact.gif"));
	public static final int baseWidth = 88;
	public static final int baseHeight = 75;
	
	public Base( Point2D.Double position ) {
		super(position, 20, image, new Dimension(baseWidth, baseHeight), 0);
	}
	
	public void draw(Graphics g2, Rectangle area, Component c ) {
		super.draw(g2, area, c);
		
		Graphics2D g = (Graphics2D) g2;
		
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
		
		int hpLeft = this.maxHealth - this.health;
		
		// 5 rondjes boven
		int x = 6;
		for( int i = 0; i < 6; i++ ) {
			if ( hpLeft > 0)
			{
				hpLeft--;
				g.setColor( Color.RED );
			}
			else
				g.setColor( Color.GREEN );
			
			g.fillOval( (int)this.position.x + x, (int)this.position.y + 6, 11, 11);
			g.setColor( Color.BLACK );
			g.drawOval( (int)this.position.x + x, (int)this.position.y + 6, 11, 11);
			
			x += 13;
		}
		
		// 3 rondjes rechts
		int y = 19;
		for( int i = 0; i < 3; i++ ) {
			if ( hpLeft > 0)
			{
				hpLeft--;
				g.setColor( Color.RED );
			}
			else
				g.setColor( Color.GREEN );
			g.fillOval( (int)this.position.x + 71, (int)this.position.y + y, 11, 11);
			g.setColor( Color.BLACK );
			g.drawOval( (int)this.position.x + 71, (int)this.position.y + y, 11, 11);
			
			y += 13;
		}
		
		// 6 rondjes beneden
		x = 71;
		for( int i = 0; i < 6; i++ ) {
			if ( hpLeft > 0)
			{
				hpLeft--;
				g.setColor( Color.RED );
			}
			else
				g.setColor( Color.GREEN );
			g.fillOval( (int)this.position.x + x, (int)this.position.y + 58, 11, 11);
			g.setColor( Color.BLACK );
			g.drawOval( (int)this.position.x + x, (int)this.position.y + 58, 11, 11);
			
			x -= 13;
		}
		
		// 3 rondjes links
		y = 45;
		for( int i = 0; i < 3; i++ ) {
			if ( hpLeft > 0)
			{
				hpLeft--;
				g.setColor( Color.RED );
			}
			else
				g.setColor( Color.GREEN );
			g.fillOval( (int)this.position.x + 6, (int)this.position.y + y, 11, 11);
			g.setColor( Color.BLACK );
			g.drawOval( (int)this.position.x + 6, (int)this.position.y + y, 11, 11);
			
			y -= 13;
		}
		
		// 2 rondjes midden
		x = 32;
		for( int i = 0; i < 2; i++ ) {
			if ( hpLeft > 0)
			{
				hpLeft--;
				g.setColor( Color.RED );
			}
			else
				g.setColor( Color.GREEN );
			
			g.fillOval( (int)this.position.x + x, (int)this.position.y + 32, 11, 11);
			g.setColor( Color.BLACK );
			g.drawOval( (int)this.position.x + x, (int)this.position.y + 32, 11, 11);
			
			x += 13;
		}
		
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
		g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
	}
	
}
